# Maintainer: Eric Bélanger <eric@archlinux.org>

pkgname=a2ps
pkgver=4.14
pkgrel=12
pkgdesc="An Any to PostScript filter"
arch=('x86_64')
url="https://www.gnu.org/software/a2ps/"
license=('GPL3')
depends=('psutils' 'imagemagick' 'perl')
makedepends=('gperf')
backup=('etc/a2ps/a2ps.cfg' 'etc/a2ps/a2ps-site.cfg')
source=(https://ftp.gnu.org/gnu/a2ps/${pkgname}-${pkgver}.tar.gz{,.sig}
        a2ps-4.13c-fnmatch-replacement.patch a2ps-4.13c-emacs.patch
	a2ps-4.13-manpage-chmod.patch a2ps-4.14-check-mempcpy.patch
	a2ps-4.14-fix-stpcpy-proto.patch a2ps-texinfo5.patch
	a2ps-4.13-security.patch
	CVE-2014-0466.patch
	CVE-2015-8107.patch
	a2ps-texinfo67.patch
        a2ps-adhere-source-date-epoch.patch)
sha1sums=('365abbbe4b7128bf70dad16d06e23c5701874852'
          'SKIP'
          '8783952d3410d8d59ed953e1db45e2ef1a0b8f65'
          '94e35a6ad9268161bec22a56d4cfb696d635994a'
          '2bb3d0a2ef2f3ff9262723e35c742a80ab0235ce'
          '6aed29c1399e79f3914b408059610f9e7c0fc38e'
          '58fa90134f1027e3f05aeb08212cbcc10f420738'
          '81269db9dd29685b0ece2539070ced3f7a8472df'
          '93a4db17edfaa99e3498c7d952c560dab49dbe42'
          '0a04f4c145d3aef8f3c7537eb00cb4040c7209c9'
          '08c51a9361eaefe76af61b70392fa5ac1c4356c7'
          'f54b6b319a5c134e0ee9be8dc9c8f80a65dc98d6'
          '6f37363785adf4357977de3d595d7938d63f0993')
validpgpkeys=('6EB39358D8328FE3CDC903A8CB6FA340E7075A54')

prepare() {
  cd ${pkgname}-${pkgver}
  sed -i -e '/^AM_C_PROTOTYPES/d' -e '/^AUTOMAKE_OPTIONS.*ansi2knr/d' \
    -e 's:AM_CONFIG_HEADER:AC_CONFIG_HEADERS:' -e 's:AM_PROG_CC_STDC:AC_PROG_CC:' \
    configure.in {contrib/sample,lib,src}/Makefile.am m4/protos.m4
  sed -i "s:^countdictstack: \0:" contrib/psset.in
  patch -p1 -i "${srcdir}/a2ps-4.13c-fnmatch-replacement.patch"
  patch -p1 -i "${srcdir}/a2ps-4.13c-emacs.patch"
  patch -p1 -i "${srcdir}/a2ps-4.13-manpage-chmod.patch"
  patch -p1 -i "${srcdir}/a2ps-4.14-check-mempcpy.patch"
  patch -p0 -i "${srcdir}/a2ps-4.14-fix-stpcpy-proto.patch"
  patch -p1 -i "${srcdir}/a2ps-texinfo5.patch"
  patch -p1 -i "${srcdir}/a2ps-4.13-security.patch"
  patch -p1 -i "${srcdir}/CVE-2014-0466.patch"
  patch -p1 -i "${srcdir}/CVE-2015-8107.patch"
  patch -p1 -i "${srcdir}/a2ps-texinfo67.patch"
  patch -p1 -i "${srcdir}/a2ps-adhere-source-date-epoch.patch"
}

build() {
  cd ${pkgname}-${pkgver}
  libtoolize --force --copy
  autoreconf --force --install -I m4 
  LIBS+="-lm" ./configure --prefix=/usr --sysconfdir=/etc/a2ps \
    --includedir=/usr/include --enable-shared --enable-nls
  make
}

package() {
  cd ${pkgname}-${pkgver}
  make DESTDIR="${pkgdir}" install
}
